package com.bwie.coupon.controller;

import com.bwie.common.doamin.dto.AddCouponDTO;
import com.bwie.common.doamin.dto.CouponLIstDTO;
import com.bwie.common.doamin.vo.CouponCategoryVO;
import com.bwie.common.doamin.vo.CouponListVO;
import com.bwie.common.doamin.vo.CouponTypeVO;
import com.bwie.common.doamin.vo.UserCouponVO;
import com.bwie.common.result.PageResult;
import com.bwie.common.result.Result;
import com.bwie.coupon.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 优惠券控制层
 *
 * @author <a href="mailto:2943147140@qq.com">刘洋朔</a>
 * @version 1.0
 * @description: 优惠券控制层
 * @date 2025/9/9 12:48
 */
@RestController
@CrossOrigin
public class CouPonController {
    /**
     * 优惠券业务层
     */
    @Autowired
    private CouponService couponService;

    /**
     * 获取优惠券列表
     * @return
     */
    @PostMapping("couponList")
    public Result<PageResult<CouponListVO>> selCouponList(@RequestBody CouponLIstDTO couponLIstDTO){
        PageResult<CouponListVO> couPonListVOPageResult = couponService.selCouponList(couponLIstDTO);
        return Result.success(couPonListVOPageResult);
    }

    /**
     * 获取优惠券类型
     * @return
     */
    @PostMapping("selCouponTypeList")
    public Result<List<CouponTypeVO>> selCouponTypeList(){
        List<CouponTypeVO> couponTypeVOs = couponService.CouponTypeVO();
        return Result.success(couponTypeVOs);
    }


    /**
     * 获取优惠券适用类型
     * @return
     */
    @PostMapping("selCouponCategoryList")
    public Result<List<CouponCategoryVO>> selCouponCategoryList(){
        List<CouponCategoryVO> couPonListVOPageResult = couponService.CouponCategoryVO();
        return Result.success(couPonListVOPageResult);
    }

    /**
     * 优惠券添加
     * @return
     */
    @PostMapping("addCoupon")
    public Result<Void> addCoupon(@RequestBody @Valid AddCouponDTO addCouponDTO){
        couponService.addCoupon(addCouponDTO);
        return Result.success();
    }

    /**
     * 优惠券删除
     * @return
     */
    @GetMapping("delCoupon/{couponId}")
    public Result<Void> delCoupon(@PathVariable("couponId") Long couponId){
        couponService.delCoupon(couponId);
        return Result.success();
    }


    /**
     * 用户领取优惠券
     * @param couponId
     * @return Void
     */
    @GetMapping("getCoupon/{couponId}")
    public Result<Void> getCoupon(@PathVariable("couponId") Long couponId){
        couponService.getCoupon(couponId);
        return Result.success();
    }

    /**
     * 拿到对应的优惠券
     * @param productId
     * @return
     */
    @GetMapping("selCouponList/{couponId}")
    public Result<List<CouponListVO>> selCouponList(@PathVariable("couponId") Long productId){
        List<CouponListVO> couponListVOS =  couponService.selCouponListById(productId);
        return Result.success(couponListVOS);
    }

    /**
     * 获取用户自己优惠券列表
     * @return
     */
    @PostMapping("ownCouponList")
    public Result<PageResult<UserCouponVO>> ownCouponList(@RequestBody CouponLIstDTO couponLIstDTO){
        PageResult<UserCouponVO> userCouponVOPageResult = couponService.ownCouponList(couponLIstDTO);
        return Result.success(userCouponVOPageResult);
    }

    /**
     * 拿到对应的优惠券的详细信息
     * @param couponId
     * @return
     */
    @GetMapping("selCouponInfo/{couponId}")
    public Result<CouponListVO> selCouponInfo(@PathVariable("couponId") Long couponId){
        CouponListVO couponListVOS =  couponService.selCouponInfo(couponId);
        return Result.success(couponListVOS);
    }

}
